module.exports = class extends think.Model
{

    async getNowTotal()
    {
        return await this.where({status: '进行中'}).count();
    }

    async getFinishedTotal()
    {
        return await this.where({status: '已结束'}).count();
    }

    async getNowItems()
    {
        let status = {"status": '进行中'};
        let fields = 'PK_CompetitionGuid as guid,Title,CoverUrl,GameStartTime,GameEndTime,Status';
        return this._getItems(status, fields);

    }

    async getFinishedItems()
    {
        let status = {"status": '已结束'};
        let fields = 'PK_CompetitionGuid as guid,Title,CoverUrl,GameStartTime,GameEndTime,Status';
        return this._getItems(status, fields);
    }

    /**
     * 根据条件和字段获取数据
     * @param status obj 条件 {status: '已结束'}
     * @param field  string 查询字段  "PK_CompetitionGuid as guid,Title,CoverUrl,GameStartTime,GameEndTime,Status"
     * @returns {Promise.<*>}
     */
    async _getItems(status = {}, field = {})
    {
        return await this.where(status).field(field).select();
    }
}